<template>
  <footer class="footer">
    <span class="todo-count"
      ><strong>{{ noDoneLength }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a
          @click.prevent="aClick('all')"
          :class="{ selected: type === 'all' }"
          href="#/"
          >全部</a
        >
      </li>
      <li>
        <a
          @click.prevent="aClick('active')"
          :class="{ selected: type === 'active' }"
          href="#/active"
          >进行中</a
        >
      </li>
      <li>
        <a
          @click.prevent="aClick('completed')"
          :class="{ selected: type === 'completed' }"
          href="#/completed"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clearClick">清除已完成</button>
  </footer>
</template>
<script>
export default {
  props: ['list', 'type'],
  computed: {
    // 依赖一个或者多个值产生一个新的值
    noDoneLength () {
      const newList = this.list.filter(item => item.isDone === false)
      return newList.length
    }
  },
  methods: {
    clearClick () {
      this.$emit('clear')
    },
    aClick (str) {
      this.$emit('setType', str)
    }
  }
}
</script>
<style></style>
